
if( AccountMenu ) then

	if( AccountMenu.TitleBar ) then

		AccountMenu.TitleBar:Remove();
		AccountMenu.TitleBar = nil;
		
	end
		
	AccountMenu:Remove();
	AccountMenu = nil;

end

function CreateAccountMenu( msg )
	
	AccountMenu = CreateBPanel( "Welcome to PubGamer.org", ScrW() / 2 - 175, math.Clamp( ScrH() / 2 - 210, ScrH() * .1 + 70, 9999 ), 350, 300 );
	AccountMenu:CanClose( false );
	AccountMenu:CanDrag( false );
	AccountMenu:SetBodyColor( Color( 40, 40, 40, 220 ) );
	
	AccountMenu:AddLabel( "Hi " .. LocalPlayer():Nick() .. ",\n\nIt looks like your new to our servers, please read below\nbefore registering.\n\nPeople on this server take roleplay seriously, seriously. If\nyou do not enjoy roleplaying seriously, this is not the server\nfor you. We have other servers that may suit you better.\n\nIf you register on the forums at pubgamer.org, you will\nbe able to view server rules, apply to join factions, and get\nto know the rest of the community.\n\nIf you do not follow the rules, you will be banned.\n\nTo register with the communitys servers, enter a username\n below, and make your choice. Enjoy.", "ChatFontSub", 5, 10, Color( 255, 255, 255, 255 ) );

	local x, y = AccountMenu:GetPos();

	AccountMenu:AddLabel( "Username:", "TargetID", 8, 237, Color( 255, 255, 255, 255 ) );

	AccountMenu.UserNameEntry = vgui.Create( "DTextEntry", AccountMenu );
	AccountMenu.UserNameEntry:SetPos( x + 90, y + 242 );
	AccountMenu.UserNameEntry:SetSize( 235, 15 );
	AccountMenu.UserNameEntry:MakePopup();
	
	ApplyMaxCharacters( AccountMenu.UserNameEntry, 20 );

	AccountMenu.RegisterAccountButton = AccountMenu:AddButton( "Register me!", 100, 267);
	
	AccountMenu.RegisterAccountButton.Action = function()
	
		if( string.len( AccountMenu.UserNameEntry:GetValue() ) < 5 or
			string.len( AccountMenu.UserNameEntry:GetValue() ) > 25 ) then
		
			CreateOkPanel( "Invalid name.", "Your Username needs to be between 5 and 25 characters." );
			return;		
		
		end
		
		RunConsoleCommand( "eng_accountcreation", AccountMenu.UserNameEntry:GetValue() );
	
	end
	
	gui.EnableScreenClicker( true );
	
	print( LocalPlayer():Nick() .. ": Account menu prompted.")

end
usermessage.Hook( "ACM", CreateAccountMenu );

function RemoveAccountMenu( msg )
	
	if( AccountMenu and AccountMenu.TitleBar ) then
	
		AccountMenu.TitleBar:Remove();
		AccountMenu:Remove();

	end

end
usermessage.Hook( "EAC", RemoveAccountMenu );
usermessage.Hook( "RAM", RemoveAccountMenu );

local function DuplicateAccount( msg )

	CreateOkPanel( "Invalid name.", "That Username is taken!" );

end
usermessage.Hook( "DAC", DuplicateAccount );